<?php
class Bootstrap {
	public function __construct() {
		set_include_path(
			ROOT_DIR .
			PATH_SEPARATOR . ROOT_LIBRARY . '/' .
			PATH_SEPARATOR . ROOT_LIBRARY . '/Database/' .
			PATH_SEPARATOR . ROOT_LIBRARY . '/Ecore/' .
			PATH_SEPARATOR . ROOT_LIBRARY . '/Smarty/' .
			PATH_SEPARATOR . ROOT_LIBRARY . '/Zend/' .
			PATH_SEPARATOR . ROOT_DIR .'/' . MOD_FRONTEND .'/controllers/' .
			PATH_SEPARATOR . ROOT_DIR .'/' . MOD_FRONTEND .'/models/' .
			PATH_SEPARATOR . get_include_path()
		);
		require_once 'Zend/Loader/Autoloader.php';
		$loader = Zend_Loader_Autoloader::getInstance();
		$loader->setFallbackAutoloader(true);
		
		// config
		include_once ROOT_DIR . '/configs/config.php';
		
		// object
		$objView = new Smarty_View(MOD_NAME);
		$vrender = new Zend_Controller_Action_Helper_ViewRenderer();
		$vrender->setView($objView);
		$vrender->setViewSuffix('tpl');
		Zend_Controller_Action_HelperBroker::addHelper($vrender);
		Zend_Registry::set('objView', $objView);
		
		// database
		Database_Connect::connect($objDb);
		
		// memcache
		$objCache = new Ecore_Cache();
		Zend_Registry::set('objCache', $objCache);

	}
	public function runApp() {		
		$frontController = Zend_Controller_Front::getInstance();
		$frontController->throwExceptions(true);
		$frontController->setDefaultControllerName('index');
		//$frontController->setParam('noViewRenderer', true);
		$frontController->setControllerDirectory(array('default' => ROOT_DIR . '/' . MOD_FRONTEND . '/controllers'));		
		//--route
		$routers = $frontController->getRouter();
		$configRouter = new Zend_Config_Ini(ROOT_DIR . '/' . MOD_FRONTEND . '/configs/configUrl.ini');
		$routers->addConfig($configRouter, 'routes');		
		try {			
			$frontController->registerPlugin(new Ecore_Plugins_Controller());
			$frontController->dispatch();
		}catch (Zend_Controller_Dispatcher_Exception $e) {
			//print_r($e->getMessage());
			//exit();
			// Error 404 Action
			//Ecore_Function::redirect(LINK_404);
		} catch(Exeception $e) {
			print_r($e->getMessage());
			exit();
		}
	}
}